package likou;

import java.util.Arrays;

/**
 * @author: 唐小尊
 * @email: 1171702529@qq.com
 * @cate: 2021/07/03 09:12
 */
public class _451 {
    public String frequencySort(String s) {
        int[][] nums = new int[54][2];
        char[] chars = s.toCharArray();
        for (char c : chars) {
            nums[c - 'A'][0] = c-'A';
            nums[c - 'A'][1]++;
        }
        Arrays.sort(nums, (i1,i2)-> i2[1]-i1[1]);
        StringBuilder str = new StringBuilder();

        for (int[] ints : nums){
            char c = (char) ('A' +ints[0]);
            for (int i=0;i<ints[1];i++){
                str.append(c);
            }
        }
        return str.toString();
    }
}
